package com.example.homework4;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * （注册信息展示、启动第三方应用）Activity
 */
public class RegisterActivity extends AppCompatActivity {
    private static final String TAG = "RegisterActivity";

    private TextView mTvAccount;
    private TextView mTvConfirmCode;
    private TextView mTvPassword;
    private Button mBtnOpenBaiDu;
    private Button mBtnOpenBiliBili;
    private Button mBtnOpenEasyCloud;

    private String account;
    private String confirmCode;
    private String password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist_info);

        initView();

        initListener();

        getIntentData();

        //将账号、密码、验证码显示到相应的TextView中
        setInfoToView();
    }

    /**
     * 获取其他activity传递进来的数据
     */
    private void getIntentData() {
        Intent intent = getIntent();

        account = intent.getStringExtra(Config.KEY_ACCOUNT);
        confirmCode = intent.getStringExtra(Config.KEY_CONFIRM_CODE);
        password = intent.getStringExtra(Config.KEY_PASSWORD);
    }

    /**
     * 将账号、密码、验证码显示到相应的TextView中
     */
    private void setInfoToView() {
        mTvAccount.setText(account);
        mTvPassword.setText(password);
        mTvConfirmCode.setText(confirmCode);
    }

    private void initListener() {
        mBtnOpenBaiDu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到百度
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.setData(Uri.parse("https://m.baidu.com/"));
                startActivity(intent);
            }
        });

        mBtnOpenBiliBili.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到b站
                Intent intent = getPackageManager().getLaunchIntentForPackage(Config.PACKAGE_NAME_BILIBILI_TV);
                startActivity(intent);
            }
        });

        mBtnOpenEasyCloud.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到网易云
                Intent intent = getPackageManager().getLaunchIntentForPackage(Config.PACKAGE_NAME_NETEASE_CLOUDMUSIC);
                startActivity(intent);
            }
        });
    }

    private void initView() {
        mTvAccount = findViewById(R.id.tv_account);
        mTvConfirmCode = findViewById(R.id.tv_confirm_code);
        mTvPassword = findViewById(R.id.tv_password);

        mBtnOpenBaiDu = findViewById(R.id.btn_open_baidu);
        mBtnOpenBiliBili = findViewById(R.id.btn_open_bilibili);
        mBtnOpenEasyCloud = findViewById(R.id.btn_open_easyCloud);
    }
}